#include "Screen.h"
#include <cstddef>
// static members are initialized within
// program text files, not header files
Screen *Screen::freeStore = 0;
const int Screen::screenChunk = 24;
void * Screen::operator new( size_t size )
{
	Screen *p;
	if ( !freeStore ) {
	// linked list empty: grab a chunk
	// this call is to the global new
	size_t chunk = screenChunk * size;
	freeStore = p =reinterpret_cast< Screen* >( new char[ chunk ] );
	// now thread the memory allocated
	for ( ;p != &freeStore[ screenChunk - 1 ];++p )
		p->next = p+1;
	p->next = 0;
	}
	p = freeStore;
	freeStore = freeStore->next;
	return p;
}

void Screen::operator delete( void *p, size_t )
{
	// insert the "deleted" object back
	// into the free list
	( static_cast< Screen* >( p ) )->next = freeStore;
	freeStore = static_cast< Screen* >( p );
}